#include <QMessageBox>
#include <QProgressDialog>

#include "filter.h"

Filter::Filter()
{
    m = 5;
}

Filter::Filter(int size)
{
    setSize(size);
}

Filter::Filter(int size, QProgressDialog *pd)
{
    setSize(size);
    setProgressDialog(pd);
}

void Filter::setSize(int size)
{
    if (size % 2 == 0) {
        QMessageBox::warning(0, "Filter",
                             "The size of a kernel can not be an even number.");
        m = -1;
        return;
    }
    m = size;
    doSetSize(size);
}

void Filter::setProgressDialog(QProgressDialog *pd)
{
    progressDialog = pd;
}

bool Filter::progress(int pixel)
{
    if (progressDialog) {
        progressDialog->setValue(pixel);
        if (progressDialog->wasCanceled())
            return true;
    }
    return false;
}
